package lgMore;

import java.awt.Color;

import robocode.Robot;
import robocode.*;
public class LgMore extends AdvancedRobot  {

	 double previousEnergy = 100;
	  int movementDirection = 1;
	  int gunDirection = 1;
	  public void run() {
	    setTurnGunRight(99999);
	  }
	  public void onScannedRobot(
	    ScannedRobotEvent e) {
	      // Stay at right angles to the opponent
	      setTurnRight(e.getBearing()+90-
	         30*movementDirection);
	         
	     // If the bot has small energy drop,
	    // assume it fired
	    double changeInEnergy =
	      previousEnergy-e.getEnergy();
	    if (changeInEnergy>0 &&
	        changeInEnergy<=3) {
	         // Dodge!
	         movementDirection =
	          -movementDirection;
	         setAhead((e.getDistance()/4+25)*movementDirection);
	     }
	    // When a bot is spotted,
	    // sweep the gun and radar
	    gunDirection = -gunDirection;
	    setTurnGunRight(99999*gunDirection);
	    
	    // Fire directly at target
	    fire ( 2 ) ;
	    
	    // Track the energy level
	    previousEnergy = e.getEnergy();
	  }

	/**
	 * onHitByBullet: What to do when you're hit by a bullet
	 */
	public void onHitByBullet(HitByBulletEvent e) {
		// Replace the next line with any behavior you would like
		// Gira 180 grados
		turnRight(90);
		// Avanza 20 unidades
		ahead(20);

	}
	
	/**
	 * onHitWall: What to do when you hit a wall
	 */
	public void onHitWall(HitWallEvent e) {
		// Replace the next line with any behavior you would like
		turnRight(90);
		// Avanza 20 unidades
		ahead(20);
	}	
	
	
}
